<!--
 * @Description:分类秒杀
 * @version: v1.0
 * @Author: Wang Xi
 * @Date: 2023-5-16 10:10:00
 * @LastEditors: WangXi
 * @LastEditTime: 2023-06-15 10:31:20
-->
<template>
	<view class="classify-seckill-container">
		<c-layout>
			<c-navigation-bar slot="head" :bgColor='true' navType="search" :disabled='false' navPlaceholder="  ..."
				navThmen=line>
			</c-navigation-bar>
			<view class="container-box">
				<view class="" style="margin: 40rpx 0;" v-if="advertisingList.length>0">
					<u-swiper :height="260" :list="advertisingList" interval='5000' img-mode="" name='imgUrl' @click="clickSwiper_advertising"></u-swiper>
				</view>
				<view class="classify-seckill-circle">
					<text>
						<text> {{$t("classifySeckill.AllCategories")}}</text>
					</text>
					<view class="circle-main">
						<scroll-view :scroll-x="true" style="white-space: nowrap;height: 250rpx;">
							<view v-for="(item,index) in typeList.slice(0,typeList.length/2)" :key="item.id" @click="parentClick(item)" class="type">
								<view class="image-box">
									<!-- 		<image v-if="index<8" style="width: 160rpx;height: 160rpx;border-radius: 50%;"
								@click="typeClick(item,index)" :src="$u.file.getMedieUrl(item.image)" mode="">
							</image>
							<view v-else class="more-box" @click="typeClick({name:'more'},index)">
								···
							</view> -->
									<image style="width: 160rpx;height: 160rpx;border-radius: 50%;" :src="$u.file.getMedieUrl(item.image)"
										mode="">
									</image>

								</view>
								<!-- 				<p v-if="index<8">{{item.name}}</p>
						<p v-else>{{$t("classifySeckill.more")}}</p> -->
								<p :class="nowId==item.id?'isCheked':''">{{item.name}}</p>
							</view>

						</scroll-view>
	<scroll-view :scroll-x="true" style="white-space: nowrap;height: 250rpx;">
							<view v-for="(item,index) in typeList.slice(typeList.length/2,typeList.length)" :key="item.id" @click="parentClick(item)" class="type">
								<view class="image-box">
									<!-- 		<image v-if="index<8" style="width: 160rpx;height: 160rpx;border-radius: 50%;"
								@click="typeClick(item,index)" :src="$u.file.getMedieUrl(item.image)" mode="">
							</image>
							<view v-else class="more-box" @click="typeClick({name:'more'},index)">
								···
							</view> -->
									<image style="width: 160rpx;height: 160rpx;border-radius: 50%;" :src="$u.file.getMedieUrl(item.image)"
										mode="">
									</image>

								</view>
								<!-- 				<p v-if="index<8">{{item.name}}</p>
						<p v-else>{{$t("classifySeckill.more")}}</p> -->
								<p :class="nowId==item.id?'isCheked':''">{{item.name}}</p>
							</view>

						</scroll-view>

					</view>
				</view>
				<view class="classify-seckill-card">
					<!-- <text> {{$t("classifySeckill.AllCategories")}}</text> -->
					<text> {{$t("classifySeckill.subclassification")}}</text>

					<view class="card-main">
						<view class="" v-for="(item,index) in categoriesList" :key="item.id" @click="typeClick(item,index)">
							<view class="text">
								<h2>{{item.name}}</h2>
								<p>{{item.des}}</p>
							</view>
							<view class="image-box">
								<image style="height: 100%; width: 100%;" :src="$u.file.getMedieUrl(item.image)" mode="center"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</c-layout>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				typeList: [],
				nowId: '',
				categoriesList: [],
				advertisingList:[],
			};
		},
		onLoad() {
			this.getCategory()
			// 广告轮播图
			this.$u.post(`/app/platformAdvertisement/queryHomeInfo`).then((res) => {
			let arr = []
			arr = res.data.platformAdvertisementDetailVOS
			arr.forEach(i => {
				i.imgUrl = this.$u.file.getMedieUrl(i.imgUrl)
			})
			this.advertisingList = arr
			
			})
		},
		methods: {
			getCategory() {
				this.$u.get('/app/shopGoodsInfo/categoryAll').then((res) => {
					// console.log(d);
					// this.categoriesList=res.data
					// this.typeList=res.data.slice(0,9)
					// this.categoriesList.forEach(item=>{
					// 	let des=""
					// 	item.child.forEach(it=>{
					// 		des+=it.name
					// 	})
					// this.$set(item,"des",des)
					// })
					this.categoriesList = res.data[0].child
					this.nowId = res.data[0].id
					this.typeList = res.data

				})
			},
			// 点击广告轮播图
			clickSwiper_advertising(index) {
				let item = this.advertisingList[index]
				console.log(item.url)
					// #ifdef H5
					window.location.href = item.url;
					// #endif
					// #ifdef APP-PLUS
					plus.runtime.openURL(item.url)
			
					// #endif
			},
			searchEvent() {},
			// 点击父级类型
			parentClick(item) {
				this.categoriesList = item.child
				this.nowId = item.id
			},
			// 类型点击
			typeClick({
				id,
				name

			}, index) {
				console.log(id, name);
				if (name == 'more') {
					uni.navigateTo({
						url: "/pages/filterMenu/filterMenu"
					})
					return
				}
				uni.navigateTo({
					url: "/pages/goodsForClassify/goodsForClassify?id=" + id + '&name=' + name + '&index=' + index
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.classify-seckill-container {
		font-family: SFUIDisplay-Regular-Regular, SFUIDisplay-Regular;
		/deep/ .search-jump {
			.uni-input-placeholder {
				color: #1B1D29;
			}
		}

		.isCheked {
			background: rgba(41, 52, 208, 1);
			color: #fff;
			padding:0 10px;
			border-radius: 10px;
		}

		.container-box {

			.classify-seckill-circle,
			.classify-seckill-card {
				>text {
					color: #1B1D29;
					font-size: 52rpx;
					line-height: 78rpx;
					display: block;
					margin-bottom: 50rpx;
				}

			}

			.classify-seckill-circle {
				.circle-main {
					display: flex;
					justify-content: flex-start;
					flex-wrap: wrap;

					.type {
						display: inline-block;
						width: 220rpx;
						margin-right: 20rpx;
						text-align: center;

						p {
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							-o-text-overflow: ellipsis;

						}
					}

					>view {
						text-align: center;
						margin-bottom: 40rpx;
						width: calc((100%) / 3);
						display: flex;
						flex-direction: column;
						align-items: center;

						>.image-box {
							border: 4rpx solid #ccc;
							border-radius: 50%;
							padding: 10rpx;
							width: 120rpx;
							height: 120rpx;

							>image {
								display: block;
							}

							>.more-box {
								width: 100%;
								height: 100%;
								display: flex;
								align-items: center;
								justify-content: center;
								font-size: 80rpx;
								color: #C1C2C4;
								background-color: #F2F3F5;
								border-radius: 50%;
							}
						}


					}

				}
			}

			.classify-seckill-card {
				margin-top: 36rpx;

				.card-main {
					overflow: hidden;

					>view {
						height: 160rpx;
						width: 100%;
						display: flex;
						align-items: center;
						background-color: #F6F9FA;
						border-radius: 16rpx;
						// &:not(:first-child){
						margin-bottom: 30rpx;

						// }
						.text {
							flex: auto;
							width: 0;
							margin: 40rpx 0rpx 0rpx 40rpx;

							>h2 {
								font-size: 34rpx;
							}

							>p {
								width: 100%;
								font-size: 20rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								margin-top: 16rpx;
							}
						}

						.image-box {
							height: 95%;
							width: 240rpx;

							>img {
								height: 95%;
							}
						}

					}
				}
			}
		}
	}
</style>